package com.jh.paymentchannel.msdf.algorithm;

import java.io.File;
import java.nio.file.Files;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;

/**
 * 装载公钥证书文件
 * 
 * @author Luke
 *
 */
public class PublicKeyReader {

	/**
	 * 
	 * @param filename
	 * @return
	 * @throws Exception
	 */
	public static PublicKey get(String filename) throws Exception {
		byte[] keyBytes = Files.readAllBytes(new File(filename).toPath());
		X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
		KeyFactory kf = KeyFactory.getInstance("RSA");
		return kf.generatePublic(spec);
	}
}
